Skip to content

feat: add HTTP proxy support via environment variables#423

Open
femto wants to merge 3 commits intogoogleworkspace:mainfrom
femto:feat/proxy-support
Open

feat: add HTTP proxy support via environment variables#423
femto wants to merge 3 commits intogoogleworkspace:mainfrom
femto:feat/proxy-support

Conversation

@femto
Copy link

@femto femto commented Mar 12, 2026

Summary

When http_proxy/https_proxy/all_proxy environment variables are set, use reqwest (which natively supports proxy) for token refresh instead of yup-oauth2's hyper-based client (which doesn't support proxy).

This enables gws to work in environments that require HTTP proxy to access Google APIs (e.g., users in China).

Changes

  • Cargo.toml: Enable reqwest's default features including proxy and SOCKS support
  • src/auth.rs:
    • Add has_proxy_env() helper to detect proxy environment variables
    • Add refresh_token_with_reqwest() for proxy-aware token refresh
    • When proxy env vars are detected, use reqwest directly instead of waiting for yup-oauth2's hyper client to timeout

Testing

Tested in an environment requiring HTTP proxy:

export https_proxy=http://127.0.0.1:7890
gws drive files list --params '{"pageSize": 5}'
# Works! Completes in ~2 seconds

Without this change, the command would hang waiting for hyper's connection timeout, then fail.

Fixes #422

@femto femto requested a review from jpoehnelt as a code owner March 12, 2026 04:42
@changeset-bot
Copy link

changeset-bot bot commented Mar 12, 2026

🦋 Changeset detected

Latest commit: 9bf3701

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@googleworkspace/cli Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@google-cla
Copy link

google-cla bot commented Mar 12, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@googleworkspace-bot
Copy link
Collaborator

/gemini review

@femto
Copy link
Author

femto commented Mar 12, 2026

@google-cla check

@femto
Copy link
Author

femto commented Mar 14, 2026

hello, the cla bot seemed to check co-author claude code noreply@anthropic.com ,
does it matter?

@dumko2001
Copy link

u can ask claude to remove coauthor submit if you want and then remove that previous commit , so then it wouldn't have cla error

@femto femto force-pushed the feat/proxy-support branch from 3758274 to d65de32 Compare March 16, 2026 02:54
@googleworkspace-bot
Copy link
Collaborator

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces HTTP proxy support by leveraging reqwest for token refresh and the initial login flow when proxy environment variables are set. The implementation correctly addresses the problem described. My review identifies several opportunities to enhance maintainability and robustness. Specifically, I've pointed out duplicated code for proxy detection. I've also suggested improvements to error handling to prevent potential panics and a refactoring to simplify a complex conditional block. Please see the specific comments for details.

femto added 3 commits March 16, 2026 11:13
When http_proxy/https_proxy/all_proxy environment variables are set,
use reqwest (which natively supports proxy) for token refresh instead
of yup-oauth2's hyper-based client (which doesn't support proxy).

This enables gws to work in environments that require HTTP proxy to
access Google APIs (e.g., users in China).

Changes:
- Cargo.toml: Enable reqwest's default features including proxy support
- src/auth.rs: Add proxy-aware token refresh using reqwest as fallback

Fixes googleworkspace#422
When proxy env vars are set, use a custom OAuth flow with reqwest
for token exchange instead of yup-oauth2's hyper-based client.

Changes to auth_commands.rs:
- Add login_with_proxy_support() for proxy-aware OAuth login
- Add exchange_code_with_reqwest() for token exchange via reqwest
- Detect proxy env vars and choose appropriate flow
@femto femto force-pushed the feat/proxy-support branch from d65de32 to 9bf3701 Compare March 16, 2026 03:22
@googleworkspace-bot
Copy link
Collaborator

/gemini review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces HTTP proxy support for token refresh and the initial authentication flow. When proxy-related environment variables are detected, reqwest is used for network requests instead of yup-oauth2's default hyper-based client, which lacks proxy support. The changes look solid and well-tested.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support HTTP proxy environment variables (http_proxy/https_proxy)

3 participants